package no.kolstad.movies.model;

import java.util.Date;
import java.util.HashSet;
import java.util.Set;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.JoinTable;
import javax.persistence.ManyToMany;
import org.apache.commons.lang.builder.ToStringBuilder;


/**
 *  Copyright [2008] Christopher Kolstad
 * Licensed under the Apache License, Version 2.0 (the "License"); 
 * you may not use this file except in compliance with the License. 
 * You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 
 * Unless required by applicable law or agreed to in writing, software distributed under the License 
 * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and limitations under the License. 
 */

/**
 *
 * @author chriswk
 */
@Entity
public class Actress extends BaseObject {
    private static final long serialVersionUID = 916885988649894684L;
    
    
    private Long id;
    private String firstName;
    private String lastName;
    private Date birthDate;
    private Set<Movie> movies = new HashSet<Movie>();

    @ManyToMany(fetch = FetchType.EAGER) 
    @JoinTable(
            name="actress_movie",
            joinColumns = { @JoinColumn( name="actress_id") },
            inverseJoinColumns = @JoinColumn( name="movie_id")
    )    
    public Set<Movie> getMovies() {
        return movies;
    }
    
    public void setMovies(Set<Movie> movies) {
        this.movies = movies;
    }

    public Date getBirthDate() {
        return birthDate;
    }

    public void setBirthDate(Date birthDate) {
        this.birthDate = birthDate;
    }

    public String getFirstName() {
        return firstName;
    }

    public void setFirstName(String firstName) {
        this.firstName = firstName;
    }

    @Id @GeneratedValue(strategy=GenerationType.AUTO)
    public Long getId() {
        return id;
    }

    public void setId(Long id) {
        this.id = id;
    }

    public String getLastName() {
        return lastName;
    }

    public void setLastName(String lastName) {
        this.lastName = lastName;
    }

  
    @Override
    public boolean equals(Object obj) {
        if (obj == null) {
            return false;
        }
        if (getClass() != obj.getClass()) {
            return false;
        }
        final Actress other = (Actress) obj;
        if (this.id != other.id && (this.id == null || !this.id.equals(other.id))) {
            return false;
        }
        if (this.firstName != other.firstName && (this.firstName == null || !this.firstName.equals(other.firstName))) {
            return false;
        }
        if (this.lastName != other.lastName && (this.lastName == null || !this.lastName.equals(other.lastName))) {
            return false;
        }
        return true;
    }

    @Override
    public int hashCode() {
        int hash = 7;
        hash = 17 * hash + (this.firstName != null ? this.firstName.hashCode() : 0);
        hash = 17 * hash + (this.lastName != null ? this.lastName.hashCode() : 0);
        hash = 17 * hash + (this.birthDate != null ? this.birthDate.hashCode() : 0);
        return hash;
    }

    @Override
    public String toString() {
        return new ToStringBuilder(this)
                .append("ID: ")
                .append(id)
                .append("Firstname ")
                .append(firstName)
                .append("Lastname ")
                .append(lastName)
                .append("Birthdate ")
                .append(birthDate)
                .toString();
    }
}
